package main

func main() {

}

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

/**
 *	kthSmallest
 *	@Description: 栈先进后出
 *	@param root *TreeNode
 *	@param k int
 *	@return int
 */
func kthSmallest(root *TreeNode, k int) int {
	sort := make([]int, 0)
	var back func(root *TreeNode)

	back = func(root *TreeNode) {
		if root == nil {
			return
		}
		back(root.Left)
		sort = append(sort, root.Val)
		back(root.Right)
	}
	back(root)
	return sort[len(sort)-k]
}
